package com.wei.czz.framework.blog.controller;

import com.wei.czz.common.annotation.Auth;
import com.wei.czz.common.dto.blog.BlogDto;
import com.wei.czz.common.tool.PageDto;
import com.wei.czz.common.tool.Result;
import com.wei.czz.common.vo.blog.BlogFormVo;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import com.wei.czz.framework.blog.service.BlogIssueService;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2022-02-20 14:10:03
 * className: BlogIssueController 系统已发布博客操作请求接口类
 * version: 1.0
 * description:
 */
@RestController
@RequestMapping("sys/blog-issue")
@AllArgsConstructor
public class BlogIssueController {

    private static final Logger log = LoggerFactory.getLogger(BlogIssueController.class);

    private final BlogIssueService blogIssueService;

    /**
     * 分页查询用户所有已发布博客标题列表接口
     *
     * 调用方：
     *  1、浏览器-后台管理页面-博客评论管理页面调用
     * @param blogFormVo 博客标题列表请求参数对象
     * @return 请求结果
     */
    @PostMapping("/title/list")
    @Auth(permit = "blog:list")
    public Result<PageDto<BlogDto>> getBlogTitleList(@RequestBody BlogFormVo blogFormVo) {
        log.info("开始分页查询用户所有已发布博客标题列表业务。{}", blogFormVo);

        if (blogFormVo.getSortType() == null) {
            log.info("分页查询用户所有已发布博客标题列表接口请求参数错误");
            return Result.paramFail();
        }
        if (blogFormVo.getPage() == null || blogFormVo.getLimit() == null) {
            log.info("分页查询用户所有已发布博客标题列表接口分页参数错误");
            return Result.pageFail();
        }

        PageDto<BlogDto> page = blogIssueService.getBlogTitleList(blogFormVo);

        log.info("分页查询用户所有已发布博客标题列表结束");
        return Result.success(page);
    }

}
